﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace Pong_Project.Views
{
    class ScoreLimitSettings : View
    {
        private string header, scoreLimit, text1, text2;
        private SpriteFont headerFont, textFont;
        private Vector2 headerPos, scoreLimitPos, text1Pos, text2Pos;
        private Vector2 headerOrigin, scoreLimitOrigin, text1Origin, text2Origin;
        private int scoreLimitEntry = Score.WinningScore;
        private int minScore = 0;

        public ScoreLimitSettings()
            : base()
        {
            header = "Set the Score Limit";
            headerPos = new Vector2(Game.WindowWidth / 2, 10);

            scoreLimit = "" + Score.WinningScore;
            scoreLimitPos = new Vector2(Game.WindowWidth / 2, Game.WindowHeight / 2 - 150);
            text1 = "Use up and down key to change scorelimit";
            text1Pos = new Vector2(Game.WindowWidth / 2, Game.WindowHeight / 2 - 100);
            text2 = "Press enter when satisfied ";
            text2Pos = new Vector2(Game.WindowWidth / 2, Game.WindowHeight / 2 - 75);

        }

        public override void LoadContent(ContentManager content)
        {
            headerFont = content.Load<SpriteFont>("Text");
            textFont = content.Load<SpriteFont>("Text");
            headerOrigin = headerFont.MeasureString(header) / 2;
            scoreLimitOrigin = textFont.MeasureString(scoreLimit) / 2;
            text1Origin = textFont.MeasureString(text1) / 2;
            text2Origin = textFont.MeasureString(text2) / 2;
        }

        public override void Update(GameTime gameTime)
        {
            if (Controls.MenuDown && scoreLimitEntry > 0)
                scoreLimitEntry--;
            else if (Controls.MenuUp && scoreLimitEntry - 1 >= minScore)
                scoreLimitEntry++;

            Score.WinningScore = scoreLimitEntry;

            if (Controls.Enter) ViewManager.State = GameState.Settings;
        }

        public override void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.DrawString(headerFont, header, headerPos, Color.White, 0, headerOrigin, 1.0f, SpriteEffects.None, 0.5f);
            spriteBatch.DrawString(textFont, "" + scoreLimitEntry, scoreLimitPos, Color.White, 0, scoreLimitOrigin, 1.0f, SpriteEffects.None, 0.5f);
            spriteBatch.DrawString(textFont, text1, text1Pos, Color.White, 0, text1Origin, 0.7f, SpriteEffects.None, 0.5f);
            spriteBatch.DrawString(textFont, text2, text2Pos, Color.White, 0, text2Origin, 0.7f, SpriteEffects.None, 0.5f);


        }
    }
}
